<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-mpMerchantWallet-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">渠道标识：</label>
				<div class="col-sm-8">
					<select id="channelId" name="channelId" class="form-control"></select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">商户标识：</label>
				<div class="col-sm-8">
					<select id="merchantId" name="merchantId" class="form-control"></select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">钱包类型标识：</label>
				<div class="col-sm-8">
					<select id="walletKindId" name="walletKindId" class="form-control"></select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">余额：</label>
				<div class="col-sm-8">
					<input id="accountBalance" name="accountBalance" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">冻结金额：</label>
				<div class="col-sm-8">
					<input id="frozenBalance" name="frozenBalance" class="form-control" type="text">
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		// 初始化钱包、渠道、商户选项
		initSelect($("#walletKindId"),"basedata/walletkind/list");
		initSelect($("#channelId"),"channel/channelInfo/list");
		initSelect($("#merchantId"),"merchant/merchantInfo/list");

		var prefix = ctx + "merchant/wallet";

		// 表单校验
		$.validator.addMethod("regex",function (value, element, params) {
			var exp = new RegExp(params);
			return exp.test(value);
		},"请输入整数数字");
		$("#form-mpMerchantWallet-add").validate({
			rules:{
				accountBalance:{
					required:true,
					regex:"^-?[0-9]\\d*$"
				},
				frozenBalance:{
					required:true,
					regex:"^-?[0-9]\\d*$"
				}
			},
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-mpMerchantWallet-add').serialize());
	        }
	    }

		// 初始化下拉菜单选项
		function initSelect(i,url) {
			$.post(ctx + url ,function (data) {
				var option = "";
				$.each(data.rows,function (index,value) {
					option += "<option value='"+value.id+"'>"+value.name+"</option>";
				});
				i.html(option);
			});
		}
	</script>
</body>
</html>
